myApp.directive('listTable', [function() {
    return {
        restrict: 'AE',
        templateUrl: 'model/listTable/listTable.html',
        replace: true,
        scope: {
            title:'=',
            list:'='
        },
        controller:function($scope){
            $scope.checkAll=false;
            angular.forEach($scope.list,function (item,index) {
                item['checked']=false;
            });
            $scope.selectAll=function () {
                if($scope.checkAll){
                    angular.forEach($scope.list,function (item,index) {
                        item.checked=true;
                    });
                }else{
                    angular.forEach($scope.list,function (item,index) {
                        item.checked=false;
                    });
                }
            }

            $scope.checkRow=function(checkItem,$event){
                checkItem.checked=!checkItem.checked;
                $scope.changeCheckAll($event);
            }
            $scope.changeCheckAll=function($event){
                $event.stopPropagation();
                var i=0;
                angular.forEach($scope.list,function (item,index) {
                    if(item.checked){
                        i++;
                    }else{
                        return false;
                    }
                });
                if(i==$scope.list.length){
                    $scope.checkAll=true;
                }else{
                    $scope.checkAll=false;
                }
            }
            
            
            $scope.$on('changeListTable',function(event,data){
            	$scope.checkAll=data.checkAll
            	
            });

        }
    };
}]);